﻿using IMark.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMark.Admin.Orders
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Utils.CheckAuthentication())
            {
                //if (!IsPostBack)
                {
                    LoadData();
                }
            }
        }
        private void LoadData()
        {
            info.InnerHtml = string.Empty;
            if ((string)Session["Info"] != "")
            {
                info.InnerHtml = (string)Session["Info"];
                Session["Info"] = "";
            }

            List<HOA_DON> dataOrders = HoaDonModels.GetAll();
            if (dataOrders.Count > 0)
            {
                StringBuilder str = new StringBuilder();
                foreach (var item in dataOrders)
                {
                    string urlViewDetail = ResolveClientUrl("~/Admin/Orders/ViewDetail.aspx?ID=" + item.MaHD);                    
                    string status = "Chưa thanh toán";                    
                    if (item.TrangThai == 1)
                        status = "Đã thanh toán";                    
                    str.Append("<tr class=\"odd gradePhone\">");
                    str.Append("<td>" + item.MaHD + "</td>");
                    str.Append("<td>" + item.HoTen + "</td>");
                    str.Append("<td>" + item.DienThoai + "</td>");
                    str.Append("<td>" + item.Email + "</td>");
                    str.Append("<td>" + item.NgayDat.ToString("dd/MM/yyyy") + "</td>");
                    str.Append("<td>" + item.ThanhTien.ToString("###,###") + "</td>");
                    str.Append("<td>" + status + "</td>");                    

                    str.Append("<td class=\"tbitem-action text-center\">");
                    str.Append("<a href=\"" + urlViewDetail + "\" class=\"btn btn-primary btn-circle\" title=\"Xem chi tiết\">");
                    str.Append("<i class=\"fa fa-eye\"></i>");
                    str.Append("</a>");                   
                    str.Append("</td>");
                    str.Append("</tr>");
                }
                lstOrders.InnerHtml = str.ToString();
            }
        }
    }
}